<?php

namespace App\Service;

use App\Model\Shop;

class ShopService
{
    protected $shop;
    protected $goods;
    protected $shopGoods;

    /**
     * 根据店铺id获取店铺关系信息
     * @param $shopId
     * @return array
     */
    public function shopRelation($shopId)
    {
        $shop = Shop::where(['shop_id' => $shopId])
                ->first(['shop_id', 'user_id', 'parent_shop_id', 'shop_switch', 'shop_name', 'shop_logo_url', 'default_discount', 'category_type'])
                ->toArray();
        if (empty($shop)) {
            return [];
        }
        //分销店铺时
        if ($shop['parent_shop_id'] > 0) {
            $parentShop = Shop::where(['shop_id' => $shop['parent_shop_id']])
                            ->first(['shop_id', 'user_id', 'parent_shop_id', 'shop_switch', 'shop_name', 'shop_logo_url', 'default_discount', 'category_type'])
                            ->toArray();
        }

        $shopInfoArray = [];
        if ($shop['parent_shop_id'] > 0) {
            $shopInfoArray['fenxiao'] = 1;
            $shopInfoArray['main_shop'] = $parentShop;
            $shopInfoArray['this_shop'] = $shop;
        } else {
            $shopInfoArray['fenxiao'] = 0;
            $shopInfoArray['main_shop'] = $shop;
        }

        return $shopInfoArray;
    }
}
